package com.example.fouroperations;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import java.text.DecimalFormat;

public class ResultActivity extends AppCompatActivity {

    public static final String TAG ="AnswerActivity";
    int quesNum;
    float totalScore;
    int rightQuesNum;
    int totalTime;
    float preScore;

    TextView totalScoreText;
    TextView accuracyText;
    TextView totalTimeText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_result);

        //从答题页面获取数据
        Intent resIntent = getIntent();
        Bundle resBdl = resIntent.getExtras();
        quesNum = resBdl.getInt("ques_num",0);
        totalScore = resBdl.getFloat("totalScore",0.0f);
        rightQuesNum = resBdl.getInt("rightQuesNum",0);
        totalTime = resBdl.getInt("totalTime",0);
        preScore = resBdl.getFloat("preScore",0.0f);

        //计算准确率
        float accuracy = (float)rightQuesNum/quesNum*100;
        //DecimalFormat decimalFormat=new DecimalFormat(".00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
        String accuracyStr = String.format("%.2f",accuracy);//format 返回的是字符串

        //计算满分
        float fullScore = preScore*quesNum;

        totalScoreText = findViewById(R.id.totalScore);
        accuracyText = findViewById(R.id.accuracy);
        totalTimeText = findViewById(R.id.totalTime);

        totalScoreText.setText(String.valueOf(totalScore)+"/"+fullScore);
        accuracyText.setText(accuracyStr+"%");
        totalTimeText.setText(totalTime+"s");

    }

    //返回主页
    public void homeClick(View btn){

        Intent homeIntent = new Intent(this, com.example.fouroperations.MainActivity.class);
        startActivity(homeIntent);
    }
}